/**
 * 后台功能
 * */


(function () {
})();


//获取功能列表
function getList(){
    $.ajax({
        type: apis.peizhenIndex.method,
        url: apis.peizhenIndex.url,
        data: {},
        success: function (res) {
            console.log(res);
            var h = '', i, tbody = $('tbody');
            if (res.code < 0) {
                //msgPop({msg: res.msg});
                h = '';
                h += '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            tbody.html(getHtml(res.data));
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}
//HTML
function getHtml(d){
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].id + '</td>';
        h += '<td>' + d[i].title + '</td>';
        h += '<td>' + d[i].pat_name + '</td>';
        h += '<td>' + d[i].pat_phone + '</td>';
        h += '<td>' + d[i].doc_name + '</td>';
        h += '<td style="width: 80px;">' + d[i].start_time + '<br>-<br>' + d[i].end_time + '</td>';
        h += '<td>' + d[i].delay + '</td>';
        h += '<td>' + d[i].yiyuan_name + '</td>';
        h += '<td>' + d[i].price + '</td>';
        h += '<td>' + d[i].status_name + '</td>';
        h += '<td>' + d[i].addtime + '</td>';
        h += '<td class="f-14">';
        h += '<a href="javascript:;" onclick="lay_show(\'订单详情\',\'peizhen-show.html\', ' + d[i].id + ');">';
        h += '详情';
        h += '</a>';
        //if (d[i].status == 3) {
        //    h += '-';
        //} else {
        //    h += '<a href="javascript:;" onclick="lay_edit(\'编辑\',\'yiyuan-edit.html\', ' + d[i].id + ');">';
        //    h += '编辑';
        //    h += '</a>';
        //}
        h += '</td>';
        h += '</tr>';
    }
    return h;
}


//详情
function lay_show(title,url,id,w,h){
    url += '?id=' + id;
    layer_show(title,url,w,h);
}


//获取一个
function getOne(v){
    $.ajax({
        type: apis.peizhenOne.method,
        url: apis.peizhenOne.url,
        data: { id: v },
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                msgPop({msg: res.msg}); return
            }
            var d = res.data;
            $('#title').html(d.title);
            $('#pat_name').html(d.pat_name);
            $('#pat_phone').html(d.pat_phone);
            $('#doc_name').html(d.doc_name);
            $('#fwtime').html(d.start_time + '<br>至<br>' + d.end_time);
            $('#delay').html(d.delay);
            $('#yiyuan_name').html(d.yiyuan_name);
            $('#price').html(d.price);
            $('#status_name').html(d.status_name);
            $('#addtime').html(d.addtime);
            $('#robtime').html(d.robtime);
            $('#doortime').html(d.doortime);
            $('#finishtime').html(d.finishtime);
        },
        error: function () {
            console.log('错误了！');
        }
    });
}